package com.project.service.impl;

import com.project.bean.FacilitiesBean;
import com.project.dao.IFacilitiesDao;
import com.project.dao.IRoomDao;
import com.project.dao.impl.FacilitiesDaoImpl;
import com.project.dao.impl.RoomDaoImpl;
import com.project.service.IFacilitiesService;
import com.project.service.IRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class FacilitiesServiceImpl implements IFacilitiesService {
    @Autowired
    private IFacilitiesDao dao ;
    @Autowired
    private IRoomDao dao1 ;

  @Override
  public List<FacilitiesBean> findByRoomId(Integer roomId) {
    return dao.findByRoomId(roomId);
  }

  @Override
  public void updateState(Integer id, Integer roomId) {
     dao.updateState(id,"已解决");
     int num = dao.findFacilitiesNum(roomId,"未解决");
     if (num==0){
       dao1.updateRoom(roomId,"正常");
     }
  }

  @Override
  public void add(FacilitiesBean facilities) {
    dao.add(facilities);
    dao1.updateRoom(facilities.getRoomBean().getId(),"设施损坏");
  }
  }
